package com.hckjsec.cloud.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.cloud.domain.AppletsPublicTable;
import com.hckjsec.cloud.service.IAppletsPublicTableService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 小程序格下载Controller
 * 
 * @author cyt
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/system/appletstable")
public class AppletsPublicTableController extends BaseController
{
    @Autowired
    private IAppletsPublicTableService appletsPublicTableService;

    /**
     * 查询小程序格下载列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppletsPublicTable appletsPublicTable)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsPublicTable.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsPublicTable> list = appletsPublicTableService.selectAppletsPublicTableList(appletsPublicTable);
        return getDataTable(list);
    }

    /**
     * 导出小程序格下载列表
     */
    @Log(title = "小程序格下载", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletsPublicTable appletsPublicTable)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsPublicTable.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsPublicTable> list = appletsPublicTableService.selectAppletsPublicTableList(appletsPublicTable);
        ExcelUtil<AppletsPublicTable> util = new ExcelUtil<AppletsPublicTable>(AppletsPublicTable.class);
        return util.exportExcel(list, "table");
    }

    /**
     * 获取小程序格下载详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appletsPublicTableService.selectAppletsPublicTableById(id));
    }

    /**
     * 新增小程序格下载
     */
    @Log(title = "小程序格下载", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletsPublicTable appletsPublicTable)
    {
        appletsPublicTable.setOperator(SecurityUtils.getUserId());
        appletsPublicTable.setDeptId(SecurityUtils.getDeptId());
        return toAjax(appletsPublicTableService.insertAppletsPublicTable(appletsPublicTable));
    }

    /**
     * 修改小程序格下载
     */
    @Log(title = "小程序格下载", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletsPublicTable appletsPublicTable)
    {
        return toAjax(appletsPublicTableService.updateAppletsPublicTable(appletsPublicTable));
    }

    /**
     * 删除小程序格下载
     */
    @Log(title = "小程序格下载", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appletsPublicTableService.deleteAppletsPublicTableByIds(ids));
    }
}
